package com.william.jdbcplus.core.condition.segment;

import com.william.jdbcplus.core.enums.SqlKeyword;
import com.william.jdbcplus.core.enums.WrapperKeyword;

import java.util.function.Predicate;

/**
 * 匹配片段
 *
 * @author niliwei
 */
public enum MatchSegment {
    INNER_JOIN(i -> i == SqlKeyword.INNER_JOIN),
    LEFT_JOIN(i -> i == SqlKeyword.LEFT_JOIN),
    RIGHT_JOIN(i -> i == SqlKeyword.RIGHT_JOIN),
    SELECT(i -> i == SqlKeyword.SELECT),
    FROM(i -> i == SqlKeyword.FROM),
    DELETE(i -> i == SqlKeyword.DELETE),
    UPDATE(i -> i == SqlKeyword.UPDATE),
    SET(i -> i == SqlKeyword.SET),
    WHERE(i -> i == SqlKeyword.WHERE),
    GROUP_BY(i -> i == SqlKeyword.GROUP_BY),
    ORDER_BY(i -> i == SqlKeyword.ORDER_BY),
    NOT(i -> i == SqlKeyword.NOT),
    AND(i -> i == SqlKeyword.AND),
    OR(i -> i == SqlKeyword.OR),
    AND_OR(i -> i == SqlKeyword.AND || i == SqlKeyword.OR),
    EXISTS(i -> i == SqlKeyword.EXISTS),
    HAVING(i -> i == SqlKeyword.HAVING),
    UNION(i -> i == SqlKeyword.UNION),
    UNION_All(i -> i == SqlKeyword.UNION_All),
    APPLY(i -> i == WrapperKeyword.APPLY);

    private final Predicate<ISegment> predicate;

    MatchSegment(Predicate<ISegment> predicate) {
        this.predicate = predicate;
    }

    public boolean match(ISegment segment) {
        return getPredicate().test(segment);
    }

    protected Predicate<ISegment> getPredicate() {
        return predicate;
    }
}
